#pragma once
#include <cstring>
#include <cstdlib>
#include <cstring>
#include <shadow.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#define USER_NAME "please input a valid user name:\n"
#define PASSWORD "please input the right password:\n"
enum CmdType
{
    CMD_TYPE_PWD = 1,
    CMD_TYPE_LS,
    CMD_TYPE_CD,
    CMD_TYPE_MKDIR,
    CMD_TYPE_RMDIR,
    CMD_TYPE_PUTS,
    CMD_TYPE_GETS,
    CMD_TYPE_NOTCMD,
    // V1 用linux系统的文件中的信息模拟的用户假登陆
    //  TASK_LOGIN_SECTION1 = 100,
    //  TASK_LOGIN_SECTION1_RESP_OK,
    //  TASK_LOGIN_SECTION1_RESP_ERROR,
    //  TASK_LOGIN_SECTION2,
    //  TASK_LOGIN_SECTION2_RESP_OK,
    //  TASK_LOGIN_SECTION2_RESP_ERROR
    LOGIN_PRE = 100,
    LOGIN_NO,
    LOGIN_POK,
    LOGIN_Q,
    LOGIN_OK,
    REGISTER_PRE,
    REGISTER_NO,
    REGISTER_POK,
    REGISTER_Q,
    REGISTER_OK
};
struct Zhuce
{
    char name[30];
    char passward[100];
    char token[50];
};
struct train_t
{
    int len;
    CmdType type;
    char buff[1000];
};
int tcpConnect(const char *ip, uint16_t port);
int recvn(int sockfd, void *buff, int len);
int sendn(int sockfd, const void *buff, int len);
int parseCommand(const char *pinput, int len, train_t *pt);
int getCommandType(const char *str);
int userLogin(int sockfd);
void putsCommand(int sockfd, train_t *pt);